<template>
    <n-tooltip trigger="hover">
        <template #trigger>
            <n-upload :max="1" action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f" list-type="image-card">上传图片</n-upload>
        </template>
        点击选择图片
    </n-tooltip>
</template>

<script lang="ts" setup>
import { ref, onBeforeMount, onMounted } from 'vue'

import { Http } from '@/libs'

const prop = defineProps({
    value: {},
})

const tips = ref<string>('')

const emit = defineEmits(['update:value'])

const doChange = (vals: any, _opts: any, path: any) => {
    tips.value = path.map((p: any) => p.n).join(' ')
    emit('update:value', vals)
}

const opts = ref([])

const execLoad = () => {
    Http.post('/comm/data/district', {}).then(resp => {
        if (resp.stat.err > 0) {
            return
        }
        opts.value = resp.data.items
        localStorage.setItem('Cache.District.Tree', JSON.stringify(resp.data.items))
    })
}

onBeforeMount(() => {
    let cache = localStorage.getItem('Cache.District.Tree')
    if (cache != '' && cache != null) {
        opts.value = JSON.parse(cache)
    } else {
        execLoad()
    }
})
onMounted(() => {})
</script>
